package feishu

import (
	"gitee.com/huerbiao/robot/pkg/logger"
	jsoniter "github.com/json-iterator/go"
)

type FeiShuFmt struct {
	StatusCode    float64
	StatusMessage string
	Extra         map[string]interface{}
}

type feishuHook struct {
	Title string
	Text  string
	Url   string
}

func NewFeiShuHook(title, text, url string) *feishuHook {
	structFeishuHook := new(feishuHook)
	structFeishuHook.Url = url
	structFeishuHook.Title = title
	structFeishuHook.Text = text
	return structFeishuHook
}

func (l *feishuHook) SendSimplyMsg() error {
	//hostname, _ := os.Hostname()
	strP := "【 ESC服务器报警: 】"

	params := make(map[string]interface{})
	params["msg_type"] = "text"
	params["content"] = map[string]interface{}{
		"title": strP + l.Title,
		"text":  strP + l.Text,
	}

	jsonResults, err := ExecCurlPost(l.Url, params, nil, "json")

	var feishuData FeiShuFmt
	_ = jsoniter.Unmarshal([]byte(jsonResults), &feishuData)
	//_ = zaplog.LogKV(zaplog.LOG_LEVEL_INFO, "FeiShu", "FeiShu", nil, "logs", params)
	logger.Info("FeiShu", "FeiShu", nil, "logs", params)

	return err
}
